(function () {
	window.initHelpPage = function (app, position, size) {
		var layer = new Kinetic.Layer();
		layer.add(createRect(0, 0, size.width - 20, size.height - 20));
		layer.add(createText(40, 40, 40, 'Как играть'));
		layer.add(createCloseButton(app, size));
        var stage = new Kinetic.Stage({
            container: 'helpPage',
            x: position.x,
            y: position.y,
            width: position.x + size.width,
            height: position.y + size.height
        });
        stage.add(layer);
        return stage;
	};
	function createCloseButton (app, size) {
		var button = createButton(size.width - 140, 20, 100, 40, 'Закрыть');
		button.on('click', function () {
			app.moveToBottom('helpPage');
		});
		return button;
	}

	function createButton (x, y, width, height, text) {
		var button = new Kinetic.Group();
		button.add(createRect(x, y, width, height));
		button.add(createText(x, y, 20, text));
		button.on('mouseover', function() {
			document.body.style.cursor = 'pointer';
		});
		button.on('mouseout', function() { document.body.style.cursor = 'default'; });
		return button;
	}
	function createRect (x, y, width, height) {
		return window.EngineWrapper.rect(x, y, width, height);
	}
	function createText (x, y, fontSize, text) {
		var el = new Kinetic.Text({
			x: x,
			y: y,
			text: text,
			fontSize: fontSize,
			fill: '#555',
			padding: 10,
			align: 'center'
		});
		return el;
	}
})();